﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DAL;
using System.Data;
using System.Data.SqlClient;

namespace BUS
{
    public class SachBUS : SqlDataProvider
    {
        SqlDataProvider db = new SqlDataProvider();
        public DataTable showsach()
        {
            string sql = "showSach";
            return db.myTable_sp(sql);
        }
        public DataTable showDanhMucSach()
        {
            return db.myTable_sp("sp_sel_DanhMucSach");
        }
        public void themsach(string tensach, string tacgia, string NXB, string theloai, string dongia, string soluong)
        {
            string sql = "themSach";
            SqlParameter Pmasach = new SqlParameter("TenSach", tensach);
            SqlParameter Ptacgia = new SqlParameter("TacGia", tacgia);
            SqlParameter PNXB = new SqlParameter("NXB", NXB);
            SqlParameter Ptheloai = new SqlParameter("TheLoai", theloai);
            SqlParameter Pdongia = new SqlParameter("DonGia", dongia);
            SqlParameter Psoluong = new SqlParameter("SoLuong", soluong);
            db.exe_sp(sql,Pmasach,Ptacgia,PNXB,Ptheloai,Pdongia,Psoluong);
        }
        public void xoasach(string masach)
        {
            {
                string sql = "xoaSach";
                SqlParameter Pmasach = new SqlParameter("masach", masach);
                db.exe_sp(sql,Pmasach);
            }
        }
        public void suasach(int masach, string tensach, string tacgia, string dongia, string soluong)
        {
            {
                string sql = "suaSach";
                SqlParameter Pmasach = new SqlParameter("masach", masach);
                SqlParameter Ptensach = new SqlParameter("tensach", tensach);
                SqlParameter Ptacgia = new SqlParameter("tacgia",tacgia);
                SqlParameter Pdongia = new SqlParameter("dongia",dongia);
                SqlParameter Psoluong = new SqlParameter("soluong", soluong);
                db.exe_sp(sql,Pmasach,Ptensach,Ptacgia,Pdongia,Psoluong);
            }
        }
        public DataTable timtheoten(string ten)
        {
            string sql = "timkiemSach";
            SqlParameter Pten = new SqlParameter("tensach", ten);
            return db.myTable_sp(sql, Pten);
        }
        public DataTable ThongTinKhachHang(int MaKhachHang)
        {
            SqlDataProvider db = new SqlDataProvider();
            SqlParameter[] p = new SqlParameter[1];
            p[0] = new SqlParameter("@MaKhachHang", MaKhachHang);
            return db.myTable_sp("sp_sel_KhachHang_Id", p);
        }
        public DataTable Search_Sach(string option, string TenSach, string TenTheLoai, int masach)
        {
            SqlDataProvider db = new SqlDataProvider();
            SqlParameter[] p = new SqlParameter[4];
            p[0] = new SqlParameter("@option", option);
            p[1] = new SqlParameter("@MaSach",masach);
            p[2] = new SqlParameter("@TenSach",TenSach);
            p[3] = new SqlParameter("@TenTheLoai",TenTheLoai);
            return db.myTable_sp("sp_sel_TKDanhMucSach", p);
        }
        public float toFloat(string s)
        {
            float l;
            try
            {
                float.TryParse(s, out l);
            }
            catch { l = 0; }
            return l;
        }
        public DataTable LayMaSach()
        {
            return db.myTable_sp("sp_LayMaSach");
        }
    }

}
